package com.harry.resource.inner.module.mgr;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.harry.configuration.ConstSettings;
import com.harry.decoupling.defi.tool.TimerJobManager;
import com.harry.decoupling.impl.module.RestfulMgrImpl;
import com.harry.resource.inner.entity.InnerTimerJob;
import com.harry.utility.BeanCtxUtils;
import com.harry.utility.PoEntityHelper;

public class InnerTimerJobRestfulMgr extends RestfulMgrImpl<InnerTimerJob> {

	@Override
	public void patch(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		super.patch(params, request, response, data);
		InnerTimerJob timerJob = (InnerTimerJob) PoEntityHelper.readValueByProperty(data, "data");
		if (timerJob.getIfRunning()) ttm().start(timerJob);
		else /*--------------------*/ttm().stop(timerJob);
	}

	@Override
	public void post(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		throw ConstSettings.NOT_ALLOW;
	}

	@Override
	public void delete(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		throw ConstSettings.NOT_ALLOW;
	}

	public static TimerJobManager ttm() {
		return BeanCtxUtils.getBeanByType(TimerJobManager.class);
	}
}
